package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.enums.ResultEnum;
import com.dongdongshop.page.PageResult;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.service.TbGoodsService;
import com.dongdongshop.vo.GoodsVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("goods")
public class TbGoodsController {

    private Logger logger = LoggerFactory.getLogger(TbBrandController.class);
    @DubboReference
    private TbGoodsService goodsService;


    @RequestMapping("auditYes")
    @ResponseBody
    public Result auditYes(Long[] ids){
        try {
            goodsService.updateAudit(ids);
            return Result.OK();
        }catch (Exception e){
            logger.info("增加方法异常 {}",e.toString());
            return Result.response(ResultEnum.ADD_MESSAGE_ERROE);
        }
    }
    @RequestMapping("auditNo")
    @ResponseBody
    public Result auditNo(Long[] ids){
        try {
            goodsService.updateAuditNo(ids);
            return Result.OK();
        }catch (Exception e){
            logger.info("增加方法异常 {}",e.toString());
            return Result.response(ResultEnum.ADD_MESSAGE_ERROE);
        }
    }

    @RequestMapping("show")
    public String show(){
        return "admin/goods";
    }

    @RequestMapping("listGoods")
    @ResponseBody
    public Result listGoods(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "3") Integer pageSize,
                            String name){
        try {
            PageResult<GoodsVo> listGood = goodsService.listGoods(pageNum,pageSize,name);
            return Result.OK().setData(listGood);
        }catch (Exception e){
            logger.info("查询广告信息出现异常: {}",e);
            return Result.response(ResultEnum.SELECT_MESSAGE_ERROE);
        }
    }
}
